package object2;

import java.lang.Override;

/**
 * 面向对象编程（中级部分）练习
 */
public class Object2Exercise09 {

    public static void main(String[] args) {
        /*
            编写 Doctor 类（name age job gender sal）
            相应的getter()和setter()方法，5个参数的构造器，重写父类(Object)的equals()方法：
            public boolean equals(Object obj)，并判断测试类中创建的两个对象是否相等(各属性是否相同)
         */

        Doctor d1 = new Doctor("张三", 24, "教师", "男", 5000.0);
        Doctor d2 = new Doctor("张三", 24, "教师", "男", 5000.0);
//        Doctor d2 = new Doctor("李四", 25, "学生", "女", 6000.0);
        System.out.println(d1.equals(d2));

    }
}

class Doctor{

    public String name;

    public int age;

    public String job;

    public String gender;

    public double sal;

    public Doctor(String name, int age, String job, String gender, double sal) {
        this.name = name;
        this.age = age;
        this.job = job;
        this.gender = gender;
        this.sal = sal;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Doctor) { //只有Doctor类才判断
            //向下转型，获取属性
            Doctor doctor = (Doctor) obj;
            return this.name.equals(doctor.name) && this.age == doctor.age && this.job.equals(doctor.job) && this.gender.equals(doctor.gender) && this.sal == doctor.sal;
        } else{
            return false;
        }
    }

    @Override
    public String toString() {
        return "Doctor{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                ", gender='" + gender + '\'' +
                ", sal=" + sal +
                '}';
    }
}